package com.cn.wanxi.servlet.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.INewsService;
import com.cn.wanxi.service.impl.NewsServiceImpl;
import com.cn.wanxi.util.DataEncoding;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/news/details")
public class NewsDetailsServlet extends HttpServlet {
    INewsService newsService = new NewsServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataEncoding.setCharacterEncoding(req,resp);
        DataEncoding.setJsonContentType(resp);
        int id = Integer.parseInt(req.getParameter("id"));
        NewsModel newsModel = newsService.getNews(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("newsDetails",newsModel);
        resp.getWriter().print(jsonObject);
    }
}
